package com.gc.controller.studentServlet;

import com.gc.service.StudentService;
import com.gc.service.impl.StudentServiceImpl;
import com.gc.util.result.R;
import com.gc.vo.ShowClassByStudent;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DataByStudentIdServlet", value = "/DataByStudentIdServlet")
public class DataByStudentIdServlet extends HttpServlet {
    StudentService studentService = new StudentServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        List<ShowClassByStudent> students = studentService.DataById(Long.valueOf(request.getParameter("id")));
        response.getWriter().write(gson.toJson(R.ok().data(students)));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        List<ShowClassByStudent> students = studentService.DataById(Long.valueOf(request.getParameter("id")));
        response.getWriter().write(gson.toJson(R.ok().data(students)));
    }
}
